﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _0912089
{
    public class RotateAction : ActionHelper
    {
        private float _beginAngle = 0;

        public float BeginAngle
        {
            get { return _beginAngle; }
            set { _beginAngle = value; }
        }
        private float _currentAngle = 0;

        public float CurrentAngle
        {
            get { return _currentAngle; }
            set { _currentAngle = value; }
        }
        private float _finishAngle;

        public float FinishAngle
        {
            get { return _finishAngle; }
            set { _finishAngle = value; }
        }

        public RotateAction(View view, Vector2 textureSize, float finishAngle)
        {
            View = view;
            view.Action = this;
            _finishAngle = finishAngle;
        }

        public override void  excuteAction(GameTime gameTime)
        {            
            if (_currentAngle == _finishAngle)
            {
                _isActioning = false;
                postNotification(ActionName, "Done");
            }

            _currentTotalTime += gameTime.ElapsedGameTime.Milliseconds;
            
            float circle = MathHelper.Pi * 2;
            _currentAngle = _currentTotalTime % circle;
            View.Rotation = _currentAngle;
        }

        public override void reverse()
        {
            base.reverse();

            float temp = BeginAngle;
            BeginAngle = FinishAngle;
            FinishAngle = temp;
        }
    }
}